package com.phkj.qdh.ui.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.FragmentManager
import com.phkj.qdh.R
import com.phkj.qdh.bean.HomeNoticeBean
import com.phkj.qdh.databinding.FragmentHomeNotificationDetailBinding


private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * 通告详情
 */
class HomeNotificationDetailFragment : Fragment() {
    private var param1: HomeNoticeBean? = null
    private var param2: String? = null
    private var _binding :FragmentHomeNotificationDetailBinding? = null
    private val binding get() = _binding!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getParcelable(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
        requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
             parentFragmentManager.popBackStack("notification",FragmentManager.POP_BACK_STACK_INCLUSIVE)
            }
        })
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = FragmentHomeNotificationDetailBinding.inflate(inflater,container,false)
        return binding.root
    }

    @SuppressLint("SetTextI18n")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.run {
            ivBack.setOnClickListener {
                parentFragmentManager.popBackStack("notification",FragmentManager.POP_BACK_STACK_INCLUSIVE)
            }
            tvAbout.text ="关于${param1?.name}的警务抄告"
            tvType.text =param1?.dispose
            time.text =param1?.time
            content.text =param1?.problem
            tv1.text ="特此给与${param1?.dispose}"
            if (param1?.scoreType==0){
                fen.text ="预加分${param1?.preDeductPoints}"
            }else{
                fen.text ="预减分${param1?.preDeductPoints}"
            }

        }
    }

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment HomeNotificationDetailFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance(param1: HomeNoticeBean, param2: String) =
            HomeNotificationDetailFragment().apply {
                arguments = Bundle().apply {
                    putParcelable(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}